//
//  ZiXunBottomView.m
//  JJHW_coreData
//
//  Created by lizhenqiang on 16/4/18.
//  Copyright © 2016年 HFKJ_LZQ. All rights reserved.
//

#import "ZiXunBottomView.h"
#import "JJotherViewController.h"
#define kBtnTag 100
@implementation ZiXunBottomView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
/*
@property(strong, nonatomic)UIButton *kuaiBaoBtn;
@property(strong, nonatomic)UIButton *daChengBtn;
@property(strong, nonatomic)UIButton *guanGuangBtn;
@property(strong, nonatomic)UIButton *meiShiBtn;
@property(strong, nonatomic)UIButton *shopingBtn;
 */
-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = TabBarBjNormalColor;
        _myWidth = frame.size.width;
        _myHeight = frame.size.height;
//        _requestType = ZXbottomRequestTypeKB;
//        CGFloat btnWidth = _myWidth/5;
//        CGFloat btnHeight = _myHeight;
//        CGRect btnFrame = CGRectMake(0, 0, btnWidth, btnHeight);
//        UIImage *normalImage = [UIColor imageFromColor:btnFrame andColor:TabBarBjNormalColor];
//        UIImage *selectImage = [UIColor imageFromColor:btnFrame andColor:TabBarBjSelectColor];
//        NSArray *titleArray = @[@"鲸快报",@"鲸搭乘",@"鲸观光",@"鲸美食",@"鲸购物"];
//        NSArray *imageArray = @[@"icon_kuaibao",@"icon_dacheng",@"icon_guanguang",@"icon_meishi",@"icon_gouwu"];
//        for(int i=0;i<titleArray.count;i++)
//        {
//            UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(btnWidth*i, 0, btnWidth, btnHeight)];
//            btn.tag = kBtnTag+i;
//            [btn setBackgroundImage:normalImage forState:UIControlStateNormal];
//            [btn setBackgroundImage:selectImage forState:UIControlStateSelected];
//            [btn setTitle:titleArray[i] forState:UIControlStateNormal];
//            NSString *imageName = imageArray[i];
//            [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateSelected];
//            [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
//            [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
//            btn.titleLabel.font = themeFont15;
//            btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//UIControlContentHorizontalAlignmentCenter
//            btn.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;//
//            CGFloat titlewidth = 45;
//            CGFloat imagewidth = 20;//16*20
//            CGFloat width = [NSString calculateTextWidth:22 Content:@"鲸快播" font:themeFont15];
//            if (DeviceWidth==320) {
//                
//                [btn setImageEdgeInsets:UIEdgeInsetsMake(4, (btnWidth-imagewidth)/2, 0, 0)];
//                [btn setTitleEdgeInsets:UIEdgeInsetsMake(27, ((btnWidth-38)/2-imagewidth), 0, 0)];
//            }
//            else
//            {
//                [btn setImageEdgeInsets:UIEdgeInsetsMake(4, (btnWidth-imagewidth)/2, 0, 0)];
//                [btn setTitleEdgeInsets:UIEdgeInsetsMake(27, ((btnWidth-titlewidth)/2-imagewidth), 0, 0)];
//            }
//            
//            [self addSubview:btn];
//            
//        }
//        
//        _selectedBtn = [self viewWithTag:kBtnTag];
//        _selectedBtn.selected = YES;
//////        _kuaiBaoBtn = [[UIButton alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
//        
    }
    
    return self;
}

-(void)setViewData:(NSMutableArray *)array
{
    _objArray = array;
    _requestType = ZXbottomRequestTypeFirst;
    if (array.count>0) {
        _obj = [array objectAtIndex:0];
        
        CGFloat btnWidth = _myWidth/array.count;
        CGFloat btnHeight = _myHeight;
        CGFloat imageWidth = 16;
        CGFloat imageHeight = 20;
        CGRect btnFrame = CGRectMake(0, 0, btnWidth, btnHeight);
        UIImage *normalImage = [UIColor imageFromColor:btnFrame andColor:TabBarBjNormalColor];
        UIImage *selectImage = [UIColor imageFromColor:btnFrame andColor:TabBarBjNormalColor];
//        NSArray *titleArray = @[@"鲸快报",@"鲸搭乘",@"鲸观光",@"鲸美食",@"鲸购物"];
//        NSArray *imageArray = @[@"icon_kuaibao",@"icon_dacheng",@"icon_guanguang",@"icon_meishi",@"icon_gouwu"];
        /*
         CustomButton *btn = [[CustomButton alloc] initWithFrame:CGRectMake(10+(DeviceWidth-20)/4*i, 45,(DeviceWidth-20)/4, 30)];
         CGFloat mywidth = (DeviceWidth-20)/4;
         CGFloat myheight = 30;
         btn.tag = KbtnTag+i;
         btn.normalTitleColor = [UIColor grayColor];
         btn.selectedTitleColor = kDefaultBlackColor;
         btn.selectBottomImage = tempImage;
         btn.normalBottomImage = nil;
         btn.normalLeftImage = [UIImage imageNamed:[unselectArray objectAtIndex:i]];
         btn.selectLeftImage = [UIImage imageNamed:[selectArray objectAtIndex:i]];
         [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
         */
        
        for(int i=0;i<array.count;i++)
        {
            SplashObj *obj = array[i];
            CustomButton *btn = [[CustomButton alloc] initWithFrame:CGRectMake(btnWidth*i, 0, btnWidth, btnHeight)];
            btn.tag = kBtnTag+i;
            [btn setBackgroundImage:normalImage forState:UIControlStateNormal];
            [btn setBackgroundImage:selectImage forState:UIControlStateSelected];
            btn.title = obj.name;
            btn.imageName_url = obj.icon;
            [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
            [btn setButtonSubViews:CGRectMake(0, btnHeight-24, btnWidth, 20) andLeftFrame:CGRectMake(0, 0, 0, 0) andBottomFrame:CGRectMake((btnWidth-imageWidth)/2, 5, imageWidth, imageHeight)];
            [self addSubview:btn];
            
        }
        _requestType = ZXbottomRequestTypeFirst;
        _selectedBtn = [self viewWithTag:kBtnTag];
        _selectedBtn.selected = YES;
        
    }
    
}

-(void)btnClicked:(UIButton *)sender
{
//    if (!sender.selected) {
        _selectedBtn.selected = NO;
        _selectedBtn = sender;
        _selectedBtn.selected = YES;
        if (_objArray.count>0) {
            _obj = [_objArray objectAtIndex:sender.tag-kBtnTag];
        }
        switch (sender.tag) {
            case 100:
            {
                _requestType = ZXbottomRequestTypeFirst;
                
            }
                break;
            case 101:
            {
                _requestType = ZXbottomRequestTypeSecond;
                            }
                break;
            case 102:
            {
                _requestType = ZXbottomRequestTypeThird;
                
            }
                break;
            case 103:
            {
                _requestType = ZXbottomRequestTypeFourth;
            }
                break;
            case 104:
            {
                _requestType = ZXbottomRequestTypeFifth;
                
            }
                break;
                
            default:
                break;
        }
        
        JJotherViewController *vc = [[JJotherViewController alloc] init];
        vc.titleForNav = _obj.name;
        vc.splashObj = _obj;
        [self.VC.navigationController pushViewController:vc animated:YES];
        
//        if (_block) {
//            _block(_requestType,_obj);
//        }
        //button点击直接跳入下级中  鲸快报之类
//    }
    
}

@end
